package com.martin.dms.model.hib;

import java.util.Set;

import com.martin.dms.model.Category;
import com.martin.dms.model.Delivery;
import com.martin.dms.model.Item;
import com.martin.dms.model.Purchase;
import com.martin.dms.model.Supplier;

/**
 * Hibernate item implementation.
 * 
 * @author mtsvetkov
 */
public class ItemHib implements Item {

    private Long id;

    private String name;
    private int price;
    private String description;
    private byte[] image;
    private int amount;

    private Category category;

    Set<Purchase> purchases;
    Set<Delivery> deliveries;
    Set<Supplier> suppliers;

    /**
     * Default constructor.
     */
    public ItemHib() {
    }

    /**
     * {@inheritDoc}
     */
    public Long getId() {
        return id;
    }

    /**
     * {@inheritDoc}
     */
    public int getAmount() {
        return amount;
    }

    /**
     * Sets the amount of items of this type in stock.
     * 
     * @param amount - the amount of items in stock.
     */
    public void setAmount(int amount) {
        this.amount = amount;
    }

    /**
     * {@inheritDoc}
     */
    public byte[] getImage() {
        return image;
    }

    /**
     * Sets the bytes of the image.
     * 
     * @param image - the bytes of the image.
     */
    public void setImage(byte[] image) {
        this.image = image;
    }

    /**
     * {@inheritDoc}
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name of the item.
     * 
     * @param name - the name of the item.
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * {@inheritDoc}
     */
    public String getDescription() {
        return description;
    }

    /**
     * Sets the description of the item.
     * 
     * @param description - the description of the item.
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * {@inheritDoc}
     */
    public int getPrice() {
        return price;
    }

    /**
     * Sets the price of the item.
     * 
     * @param price - the price of the item.
     */
    public void setPrice(int price) {
        this.price = price;
    }

    /**
     * {@inheritDoc}
     */
    public Category getCategory() {
        return category;
    }

    /**
     * Sets the category of this item.
     * 
     * @param category to set.
     */
    public void setCategory(Category category) {
        this.category = category;
    }

    /**
     * {@inheritDoc}
     */
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof ItemHib)) {
            return false;
        }
        final ItemHib item = (ItemHib) obj;
        if (item.getId() != null && this.getId() != null) {
            return item.getId().equals(this.getId());
        }
        return false;
    }

    /**
     * {@inheritDoc}
     */
    public int hashCode() {
        int result = 17;
        if (getId() != null) {
            result += 37 * result + getId().hashCode();
        }
        return result;
    }
}
